<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>计划列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/systemStatic/style/admin.css">
    <link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/css/public.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body>
<div style="position: relative;height: 100%;margin-top: 10px;" id="jobContentBody">
    <table class="layui-hide" id="triggerListTable" lay-filter="triggerListTable"></table>
    <!--隐藏域属性配置 -->
    <input id="jobName" name="jobName" type="hidden" value="${jobName}" />
    <!---------------------------------->
    <script type="text/html" id="triggerToolBarTop">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="addTrigger"><i class="layui-icon layui-icon-add-1"></i>添加</button>
            <button class="layui-btn layui-btn-sm" lay-event="viewTriggerList"><i class="layui-icon layui-icon-return"></i>返回</button>
        </div>
    </script>
</div>
<script type="text/html" id="triggerToolBar">
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delTrigger">删除</a>
    <a class="layui-btn layui-btn-xs" lay-event="switchTrigger">启用|禁用</a>
    <!--<a class="layui-btn layui-btn-xs" lay-event="openTrigger">启用</a>
    <a class="layui-btn layui-btn-xs" lay-event="closeTrigger">禁用</a>-->
    <a class="layui-btn layui-btn-xs" lay-event="triggerLog">日志</a>
</script>
<script src="${ctx}/public/component.js" type="text/javascript"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','table','layer','setter', 'commons'],function(){
        var table = layui.table,setter = layui.setter,$ = layui.jquery,layer = layui.layer,commons = layui.commons;

        table.render({
            elem:"#triggerListTable"
            ,url:serverPath.systemPath + setter.sysLinkPath+"scheduler/triggerList?jobName="+$("#jobName").val()
            ,cellMinWith:setter.cellMinWidth
            ,defaultToolbar: ['filter', 'print']
            ,toolbar: '#triggerToolBarTop'
            // ,page:true
            ,cols:[[
                {type:'numbers',align:'center', title: '序号'}
                ,{field:'jobName', title: '任务名称'}
                ,{field:'name', title: '计划名称'}
                ,{field:'description', title: '计划描述'}
                ,{field:'state', title: '状态',templet:function(res){
                    return res.state;
                    }}
                ,{title: '管理',align:'center',toolbar:'#triggerToolBar'}

            ]]
        });

        //头工具栏事件
        table.on('toolbar(triggerListTable)', function(obj){
            switch(obj.event){
                case 'viewTriggerList':
                    location.href= serverPath.systemPath + setter.sysLinkPath +"scheduler/view/jobList";
                    break;
                case 'addTrigger':
                    location.href= serverPath.systemPath + setter.sysLinkPath +"scheduler/view/addTrigger?jobName="+$("#jobName").val();
                    break;
            };
        });

        //监听行工具栏
        table.on('tool(triggerListTable)',function(obj){
            var data = obj.data;
            switch(obj.event){
                case "delTrigger":
                    layer.confirm('确定删除当前数据吗？', function() {
                        $.ajax({
                            url: serverPath.systemPath + setter.sysLinkPath + "scheduler/delTrigger?triggerName="+data.name,
                            type: "get",
                            dataType: 'json',
                            success: function(data) {
                                if (commons._filterRecord(data)) {
                                    layer.alert(data.msg);
                                    table.reload('triggerListTable', {});
                                } else {
                                    layer.alert(data.msg);
                                }
                            }
                        });
                    });
                    break;
                case "switchTrigger":
                    $.ajax({
                        url: serverPath.systemPath + setter.sysLinkPath + "scheduler/toggleTriggerRun?triggerName="+data.name,
                        type: "get",
                        dataType: 'json',
                        success: function(data) {
                            if (commons._filterRecord(data)) {
                                layer.alert(data.msg);
                                table.reload('triggerListTable', {});
                            } else {
                                layer.alert(data.msg);
                            }
                        }
                    });
                    break;
                case "closeTrigger":
                    $.ajax({
                        url: serverPath.systemPath + setter.sysLinkPath + "scheduler/toggleTriggerRun?triggerName="+data.name,
                        type: "get",
                        dataType: 'json',
                        success: function(data) {
                            if (commons._filterRecord(data)) {
                                // layer.alert(data.msg);
                                // table.reload('triggerListTable', {});
                            } else {
                                // layer.alert(data.msg);
                            }
                        }
                    });
                    break;
                case "triggerLog":
                    $(this).attr("href", serverPath.systemPath + setter.sysLinkPath +"sysJobLog/view/list?jobName="+data.jobName+"&baseUrl=" + serverPath.systemPath + setter.sysLinkPath+"scheduler/view/triggerList?jobName="+data.jobName);
                    break;
            }
        });
    });
</script>
</body>
</html>